﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace EdexApiClient
{
    public partial class EdexApiContext
    {
        /// <summary>
        /// Получить исходящие накладные
        /// </summary>
        /// <returns></returns>
        public IEnumerable<WH_INVOICES> GetInvoices()
        {
            return this.GetInvoices(String.Empty);
        }

        /// <summary>
        /// Получить исходящие накладные
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public IEnumerable<WH_INVOICES> GetInvoices(string search)
        {
            var uri = String.Format("Invoices/?api_key={0}", this.session.APIKEY);

            if (!String.IsNullOrEmpty(search))
                uri += "&$filter=substringof('" + search + "', DOC_NUMBER) eq true&$top=100";

            uri += "&$orderby=DOC_DATE";

            return this.GetData<List<WH_INVOICES>>(uri);
        }

        /// <summary>
        /// Получить детализацию по исходящей накладной
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public WH_INVOICES GetInvoice(string id)
        {
            return this.GetData<WH_INVOICES>(String.Format("Invoices/{0}/?api_key={1}", id, this.session.APIKEY));
        }
        /// <summary>
        /// Получить детализацию по позиции в исходящей накладной
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public WH_INVOICE_LINES GetInvoiceLine(string id)
        {
            return this.GetData<WH_INVOICE_LINES>(String.Format("InvoiceLines/{0}/?api_key={1}", id, this.session.APIKEY));
        }
    }
}